/*******************************************************************************
 * Copyright 2008 www.softao.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
/**
 * Place holder for copyright, needs to be replaced before release.
 */
package com.softao.ming.gwt.drawing2d.client.ui.impl;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.Element;

/**
 * Implementation based on the Canvas.
 */
public class GraphicsImplCanvas extends GraphicsImpl {
	private Element mElement;
	
	@SuppressWarnings("unused")
	private JavaScriptObject mJSCanvas;

	@Override
	public void initialize(Element element) {
		super.initialize(element);
		this.mElement = element;
		this.mJSCanvas = this.featchJSCanvas();
	}

	/**
	 * @return the element
	 */
	public Element getElement() {
		return mElement;
	}
	
	@Override
	public native void setFillStyle(String value) /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.fillStyle = value;
	}-*/;
	
	@Override
	public native void setStrokeStyle(String value) /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.strokeStyle = value;
	}-*/;
	
	private native JavaScriptObject featchJSCanvas() /*-{
		return this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mElement.getContext('2d');
	}-*/;
	
	@Override
	public native void fillRect(float x, float y, float width, float height) /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.fillRect(x, y, width, height);
	}-*/;

	@Override
	public native void strokeRect(float x, float y, float width, float height) /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.strokeRect(x, y, width, height);
	}-*/;

	@Override
	public native void setLineWidth(float value) /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.lineWidth = value;
	}-*/;
	
	@Override
	public native void beginPath() /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.beginPath();
	}-*/;
	
	@Override
	public native void moveTo(float x, float y) /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.moveTo(x, y);
	}-*/;
	
	@Override
	public native void lineTo(float x, float y) /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.lineTo(x, y);
	}-*/;
	
	@Override
	public native void bezierCurveTo(float cp1x, float cp1y, float cp2x, float cp2y,
			float x, float y) /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
	}-*/;
	
	@Override
	public native void quadraticCurveTo(float cpx, float cpy, float x, float y) /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.quadraticCurveTo(cpx, cpy, x, y);
	}-*/;
	
	@Override
	public native void rect(float x, float y, float w, float h) /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.rect(x, y, w, h);
	}-*/;
	
	@Override
	public native void arc(float x, float y, float radius, float startAngle,
			float endAngle, boolean anticlockwise) /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.arc(x, y, radius, startAngle, endAngle, anticlockwise);
	}-*/;
	
	@Override
	public native void fill() /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.fill();
	}-*/;
	
	@Override
	public native void closePath() /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.closePath();
	}-*/;
	
	@Override
	public native void stroke() /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.stroke();
	}-*/;
	
	@Override
	public native void save() /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.save();
	}-*/;
	
	@Override
	public native void restore() /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.restore();
	}-*/;
	
	@Override
	public native void translate(float x, float y) /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.translate(x, y);
	}-*/;
	
	@Override
	public native void setGlobalAlpha(float value) /*-{
		this.@com.softao.ming.gwt.drawing2d.client.ui.impl.GraphicsImplCanvas::mJSCanvas.globalAlpha = value;
	}-*/;
	
}
